﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcWeb.Models
{
    public static class PagerHelper
    {
        public static string Pager(string url1, int id, int count, int size, int show)
        {
            string pager = "";
            string url = url1.Contains("?") ? url1 + "&page=" : url1 + "?page=";
            pager = "<a href=\"" + url + (1) + "\"><<</a>";
            if (id != 1)
            {
                pager += "<a href=\"" + url + (id - 1) + "\"><</a>";
            }
            if (id > (show + 1))
            {
                pager += "<a href=\"" + url + (id - show - 1) + "\">..</a>";
            }

            int page_count = (count+size-1) / size;
            if (page_count == 0)
            {
                return "";
            }
            for (int i = id - show; i <= id + show; i++)
            {
                if (id == i)
                    pager += "<span>" + i + "</span>";
                else if (i > 0 && i <= page_count)
                    pager += "<a href=\"" + url + i + "\">" + i + "</a>";

            }
            if (id < page_count - show)
            {
                pager += "<a href=\"" + url + (id + show + 1) + "\">..</a>";

            }
            if (id != page_count)
            {
                pager += "<a href=\"" + url + (id + 1) + "\">></a>";
            }
            //pager += "<a href=\"" + url + page_count + "\">" + page_count + "</a>";
            pager += "<a href=\"" + url + page_count + "\">>></a>";
            return pager;
        }
    }
}